﻿using System;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;

namespace Sustainalytics.Entities
{
    [BsonIgnoreExtraElements]
    public class PortfolioMatches : IEntity
    {
        public Guid Id { get; set; }
        public Guid PortfolioId { get; set; }
        public string PortfolioName { get; set; }
        public DisplayInformation DisplayInfo { get; set; }
        public MatchedInformation MatchedInfo { get; set; }
        public Guid CompanyId { get; set; }
        public string CompanyNameUrlFriendly { get; set; }
        public string CompanyNameLowercase { get; set; }
        public string SecurityId { get; set; }
        public bool IsValid { get; set; }
        public bool Added { get; set; }
        public DateTime Created { get; set; }
        public PortfolioMatchType MatchType { get; set; }
        public string AddedByFullName { get; set; }
        public Guid AddedByUserId { get; set; }
        public string AddedByUserName { get; set; }
        public Guid AccountId { get; set; }
        public bool AddedFromCompanySearch { get; set; }
        public PortfolioSharingStatus SharingStatus { get; set; }
        public Guid GroupId { get; set; }

        [BsonIgnoreIfNull]
        public double? SecurityWeight { get; set; }
        public PortfolioUserInput GetPortfolioUserInput(Guid addedByUserId)
        {
            return new PortfolioUserInput
            {
                Id = Id,
                InsertDate = DateTime.Today,
                PortfolioId = PortfolioId,
                SecurityIdentifier = DisplayInfo.SecurityIdentifier,
                SecurityName = DisplayInfo.CustomSecurityIdentifierName,
                UserId = addedByUserId
            };
        }

        public PortfolioDetails ToPortfolioDetails()
        {
            return new PortfolioDetails(){
                Id = Id,
                PortfolioId = PortfolioId,
                DisplayInfo = DisplayInfo,
                MatchedInfo = MatchedInfo,
                CompanyId = CompanyId,
                CompanyNameUrlFriendly = CompanyNameUrlFriendly,
                CompanyNameLowercase = CompanyNameLowercase,
                SecurityId = SecurityId,
                SecurityWeight = SecurityWeight,
                IsInvalidMatch = !Added
            };
        }
    }
}
